package com.chazz.dao.impl;

import cn.hutool.db.Db;
import com.chazz.dao.CoupondDao;
import com.chazz.entity.Couponduser;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述:通过用户id查询优惠券，并通过商品分类id判断是否能够进行优惠。
 *
 * @author Chazz
 * @create 2020-09-24 9:10
 */
public class CouponDaoImpl implements CoupondDao {



    /**
     * description: IsCoupond 返回优惠券金额 <br>
     * version: 1.0 <br>
     * date: 2020/9/24 14:31 <br>
     * author: Chazz <br>
     * @param uid 用户id
     * @param categoryId 商品类别id
     * @return integer 优惠券金额
     */
    @Override
    public Integer isCoupond(Integer uid, Integer categoryId) {
        List<Couponduser> coupondusers = new ArrayList<>();
        Integer countMoney = 0;
        try {
            coupondusers= Db.use()
                .query("select * from couponduser where uid = ?", Couponduser.class, uid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        if (coupondusers.get(0).getMoney()!=null && coupondusers.get(0).getMoney()>=0) {
            countMoney = coupondusers.get(0).getMoney();
        }
        return countMoney;
    }
}
